package main

import (
	"awesomeProject1/push/plugin"
	"awesomeProject1/push/plugin/im"
	"awesomeProject1/push/server"
	"fmt"
	"github.com/gin-gonic/gin"
)

func main() {

	r := gin.Default()

	wsService := im.NewWsImService()

	// 路由映射 WebSocket 处理器
	r.GET("/ws", func(c *gin.Context) {
		wsService.HandleWebSocket(c)
	})

	r.POST("/test", func(context *gin.Context) {
		phones := context.PostFormArray("phones")
		emails := context.PostFormArray("emails")
		wsids := context.PostFormArray("wsids")
		wechats := context.PostFormArray("wechats")
		content := context.PostForm("content")

		value, exists := context.Get("phones")
		if exists {
			fmt.Println("==================>phones", value)
		}

		fmt.Println(phones)
		fmt.Println(emails)
		fmt.Println(wsids)
		fmt.Println(wechats)
		fmt.Println(content)
		msg := plugin.MsgRes{
			Phones:  phones,
			Emails:  emails,
			WsIds:   wsids,
			Wechats: wechats,
			Content: content,
		}
		server.Push(msg)
	})

	r.POST("/ping", func(context *gin.Context) {
		phones := context.PostForm("phones")
		emails := context.PostForm("emails")
		wsids := context.PostForm("wsids")
		wechats := context.PostForm("wechats")
		content := context.PostForm("content")

		fmt.Println(phones)
		fmt.Println(emails)
		fmt.Println(wsids)
		fmt.Println(wechats)
		fmt.Println(content)
		context.JSON(200, gin.H{
			"phones":  phones,
			"wsids":   wsids,
			"emails":  emails,
			"wechats": wechats,
			"content": content,
		})
	})

	// 启动 Gin 服务
	r.Run(":8080")

	//msg := plugin.MsgRes{
	//	Phones:  []string{"18810559863"},
	//	Emails:  []string{"2573166602@qq.com"}, //"whz@live.com"
	//	WsIds:   []string{"123", "124"},
	//	Wechats: []string{"luwenjing668"},
	//	Content: "Hello, this is a sample message for testing!",
	//}

}
